package com.toweave.starter.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;

import com.toweave.starter.R;
import com.toweave.starter.fragments.StaticFragment;

public class DynamicFragmentActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dynamic_fragment);

    // static_fragment = findViewById(R.id.static_fragment);
    // 获取FragmentManager
    FragmentManager fragmentManager = getSupportFragmentManager();
    // 开始一个新的FragmentTransaction
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    // 创建你的Fragment实例
    StaticFragment staticFragment = new StaticFragment();
    // 将Fragment添加到指定的容器（布局中的FrameLayout或其他容器）中
    // fragmentTransaction.add(R.id.static_fragment, staticFragment, "DynamicFragmentTag");
    fragmentTransaction.add(R.id.fl_dynamic_fragment, staticFragment, staticFragment.getTag());
    // 提交事务
    fragmentTransaction.commit();
  }
}